package com.yty.demo._4_oop;

/**
 * @author: yangtaoyao
 * @time: 2020/1/8 9:39
 * @description:
 */
public class Children extends Father{
    private String hobby="篮球";//显式初始化在父类构造方法执行结束后进行
    //    private Children children=new Children();//java.lang.StackOverflowError
    static {
        System.out.println("2-子类静态代码块");
    }
    {
        System.out.println("5-子类构造代码块");
    }
    Children(){
        System.out.println("6-子类构造方法");
        super.show();
    }
    public Children(String hobby) {
        this.hobby = hobby;
    }
    public void show(){
        System.out.println("7-子类show");
    }

    @Override
    public boolean equals(Object obj) {
        Children o=(Children)obj;
        return this.age==o.age;
    }

    public static void main(String[] args) {
        Father children=new Children();
        children.show();//运行时类型，动态绑定
        System.out.println(children.hashCode());
        System.out.println(children.toString());
    }
}
class Father{
    int age=20;
    static {
        System.out.println("1-父类静态代码块");
    }
    {
        System.out.println("3-父类构造代码块");
    }
    Father(){
        System.out.println("4-父类构造方法");
    }
    public void show(){
        System.out.println("父类show");
    }
}
/*
父类静态代码块
子类静态代码块
父类构造代码块
父类构造方法
父类age20
子类构造代码块
子类构造方法
父类age20
父类hobby篮球
子类show
* */